/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.linktco.prison.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.linktco.prison.entity.CabinetCell;
import com.linktco.prison.entity.CabinetCellUser;
import com.linktco.prison.service.ICabinetCellService;
import com.linktco.prison.service.ICabinetCellUserService;
import com.linktco.prison.vo.CabinetCellVO;
import com.linktco.prison.vo.CabinetInfoVO;
import com.linktco.prison.vo.CabinetSided;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 档案柜格 控制器
 *
 * @author BladeX
 * @since 2024-12-23
 */
@RestController
@AllArgsConstructor
@RequestMapping("/cabinet-cell")
@Api(value = "档案柜格", tags = "档案柜格接口")
public class CabinetCellController extends BladeController {

	private final ICabinetCellService cabinetCellService;
	private final ICabinetCellUserService cellUserService;


	@GetMapping("/sided-detail")
 	@ApiOperation(value = "正面背面集合", notes = "传入cabinetId")
	public R<CabinetSided> sidedList(Long cabinetId) {
		return R.data(cabinetCellService.sidedList(cabinetId));
	}

	@GetMapping("/sided-page")
	@ApiOperation(value = "柜子分页", notes = "传入cabinetId,keyword")
	public R<IPage<CabinetSided>> sidedPage(Query query,String cabinetKeyword,String userKeyword) {
		IPage<CabinetSided> page = Condition.getPage(query);
		return R.data(cabinetCellService.sidedPage(page,cabinetKeyword,userKeyword));
	}



	@PostMapping("/save")
 	@ApiOperation(value = "新增", notes = "传入cellUser")
	public R save(@RequestParam Long cellId, @RequestParam String userIds) {
		return R.status(cellUserService.customSave(cellId,Func.toLongList(userIds)));
	}


	@PostMapping("/remove")
 	@ApiOperation(value = "移除", notes = "传入ids")
	public R remove( @RequestParam Long cellId, @RequestParam String userIds) {
		return R.status(cellUserService.remove(Wrappers.<CabinetCellUser>lambdaQuery()
				.eq(CabinetCellUser::getCellId,cellId)
				.in(CabinetCellUser::getUserId,Func.toLongList(userIds))));
	}

	
}
